var app = getApp()
Page({
  data: {
    userInfo: {},
    avatarUrl: "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0", //这里放了一张灰色头像图片
    nickName: "点击获取头像和昵称", //用户昵称
  },
  onLoad: function () {


  },

  getUserProfile(){
    wx.getUserProfile({
      desc: '登录', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
    
        this.setData({
          nickName: res.userInfo.nickName,
          avatarUrl: res.userInfo.avatarUrl
        })

        wx.setStorage({    //数据缓存方法
          key: 'useni',   //关键字，本地缓存中指定的key
          data: res.rawData,    //缓存微信用户公开信息，
          success: function() {      //缓存成功后，输出提示
            console.log('写入nickName缓存成功')
          },
          fail: function() {        //缓存失败后的提示
            console.log('写入nickName发生错误')
          }
        })


        wx.setStorage({    //数据缓存方法
          key: 'nickName',   //关键字，本地缓存中指定的key
          data: res.userInfo.nickName,    //缓存微信用户公开信息，
          success: function() {      //缓存成功后，输出提示
            console.log('写入nickName缓存成功')
          },
          fail: function() {        //缓存失败后的提示
            console.log('写入nickName发生错误')
          }
        })
        wx.setStorage({    //数据缓存方法
          key: 'avatarUrl',   //关键字，本地缓存中指定的key
          data: res.userInfo.avatarUrl,    //缓存微信用户公开信息，
          success: function() {      //缓存成功后，输出提示
            console.log('写入avatarUrl缓存成功')
          },
          fail: function() {        //缓存失败后的提示
            console.log('写入avatarUrl发生错误')
          }
        })
      }
    })
   
  },



  onShow: function () {
    //请求有无邀请活动
    var that = this
    var params = {}
    params.sellerId = wx.getStorageSync('agent').id
    params.buyerId = wx.getStorageSync('userId')

    app.HttpService.youwuhud(params).then(res => {
      console.log(res)

      that.setData({
        code: res.data.code
      })
    })




    let wode = wx.getStorageSync('dengl')
    if (wode == 1) {
      that.setData({
        zhan: false
      })
    } else {
      that.setData({
        zhan: true
      })
    }


    var that = this

    // 请求悬浮窗
    var params = {
      userId: wx.getStorageSync("userId"),
      sellerId: wx.getStorageSync('agent').id
    }

    app.HttpService.qqxfc(params).then(res => {
      console.log(res, "数636363据")
      this.setData({
        xsz: res.data.data
      })
    });


  },
  toOrder(e) { // 普通订单与套餐
    let {
      stauts
    } = e.currentTarget.dataset
    wx.navigateTo({
      url: '/pages/order/list/index?stauts=' + stauts
    })
  },
  toGroupOrder(e) { //拼团订单
    let {
      stauts
    } = e.currentTarget.dataset
    wx.navigateTo({
      url: '/pages/group-buying/order-list/index?stauts=' + stauts
    })
  },
  toCar() { // 车辆管理
    wx.navigateTo({
      url: '/pages/car/list/index'
    })
  },
  toIntegral() { // 我的积分
    wx.navigateTo({
      url: '/pages/integral/myIntegral/index'
    })
  },
  // 优惠券中心
  toCoupons() {
    wx.navigateTo({
      url: '/pages/coupons/coupons',
    })
  },
  // 意见反馈
  toFeedBack() {
    wx.navigateTo({
      url: '/pages/feedback/feedback',
    })
  },
  // 意见反馈
  toFeedBacks() {
    wx.navigateTo({
      url: '/pages/dianziquan/dianziquan',
    })
  },

  // 我的收藏
  wodeshouc() {
    wx.navigateTo({
      url: '/pages/shoucang/shoucang',
    })

  },



  navigateToAddress: function () {
    wx.navigateTo({
      url: '../select-address/index'
    });
  },
  navigateToOrder: function (e) {
    var status = e.currentTarget.dataset.status
    wx.navigateTo({
      url: '../../order/list/list?status=' + status
    });
  },
  logout: function () {
    wx.navigateTo({
      url: '../../admin/login/login'
    });
  },

  jinruk: function () {
    wx.navigateTo({
      url: '/pages/login/index',
    })
  },
  yaoqing: function () {


    var d = this.data.code

    if (d == 200) {
      wx.navigateTo({
        url: '/pages/fenxiangym/index',
      })
    } else {
      wx.navigateTo({
        url: '/pages/huodongguoqi/index',
      })
    }
  },

  gerehuiy: function () {
    wx.navigateTo({
      url: '/pages/gerenzx/index',
    })
  },
  jiang: function (e) {
    console.log("抽奖")
    wx.navigateTo({
      url: '/pages/choujiang/index',
    })
  },
  // 我的会员
  wodehuiyuan: function () {
    wx.navigateTo({
      url: '/pages/wodehuiyuan/index',
    })
  },
  xiaoxitixing: function () {
    wx.navigateTo({
      url: '/pages/xiaoxitixing/index',
    })
  },
  //礼物列表
  wodeliwu: function () {
    wx.navigateTo({
      url: '/pages/liwu/index',
    })

  },
  deodeqianb: function () {
    wx.navigateTo({
      url: '/pages/tixian/index',
    })

  },
  // 我的奖品
  wodejiangpin: function () {
    wx.navigateTo({
      url: '/pages/wodejiangpin/index',
    })

  },

})